package middleware

import (
	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
)

// AuthRequired 检查管理员登录状态
func AuthRequired() gin.HandlerFunc {
	return func(c *gin.Context) {
		session := sessions.Default(c)
		adminID := session.Get("admin_id")

		if adminID == nil {
			c.Redirect(302, "/admin/login")
			c.Abort()
			return
		}

		c.Next()
	}
}
